package com.ypx;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapDemo {
   public static void main(String[] args) {
       test0();
       test1();
   }

    private static void test0() {
        TreeMap<Student, String> treeMap = new TreeMap<>();
        treeMap.put(new Student("小明", 18),"北京");
        treeMap.put(new Student("小红", 17),"上海");
        treeMap.put(new Student("小刚", 19),"深圳");
        System.out.println(treeMap);
    }
    private static void test1() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge() - o1.getAge();
            }
        });
        treeMap.put(new Student("小明", 18),"北京");
        treeMap.put(new Student("小红", 17),"上海");
        treeMap.put(new Student("小刚", 19),"深圳");
        System.out.println(treeMap);
    }
}
